package capaDominio;


import java.net.ServerSocket;
import java.net.Socket;

import javax.net.ServerSocketFactory;

import capaDatos.BaseDatos;
import capaPresentacion.RedirectedFrame;

public class ServidorPrincipal {
	private static threadWeb service;
	public static BaseDatos BD;
    private final int serverPort = 7777;

    public static void main(String[] args) {      
        new RedirectedFrame("Servidor Principal");
        BD = new BaseDatos();
        service = new threadWeb();
        service.start();
        new ServidorPrincipal().run();
    }

	public void run() {
        ServerSocketFactory ServerSocketFactory = null;
        ServerSocket ServerSocket = null;
        Socket client = null;
        try {
            ServerSocketFactory = (ServerSocketFactory) javax.net.ServerSocketFactory.getDefault();
            ServerSocket = (ServerSocket) ServerSocketFactory.createServerSocket(serverPort);
            //ServerSocket server = getServerSocket();
            int localPort = ServerSocket.getLocalPort();
            System.out.println("Servidor Principal is listening on port "+localPort+".");
            do {
            	client = (Socket) ServerSocket.accept();
                System.out.println(client.getInetAddress().toString().replace("/", ""));
                //Socket client = server.accept();
                (new ConexionUsuario(client)).start();
            } 
            while(true);
        } catch(Exception ex) {
            System.out.println("Unable to listen on "+serverPort+".");
            ex.printStackTrace();
            System.exit(1);
        }
    }
}



